package com.autumn.mybatis.criterion;

import java.util.List;
import java.util.Map;

import com.autumn.mybatis.mapper.IEntityMapper;
import com.autumn.util.ExceptionUtils;

/**
 * 实体指定查询
 * 
 * @author 杨昌国 2018-12-07 17:40:37
 */
public class EntitySpecifyQuery<TEntity> extends SpecifyQuery {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4799415408146164556L;

	private final Class<TEntity> entityClass;

	/**
	 * 实例化 EntityQuery 类新实例
	 * 
	 * @param entityClass 实体类型
	 */
	public EntitySpecifyQuery(Class<TEntity> entityClass) {
		super(entityClass);
		this.entityClass = ExceptionUtils.checkNotNull(entityClass, "entityClass");
	}

	/**
	 * 获取实体类型
	 * 
	 * @return
	 */
	public final Class<TEntity> getEntityClass() {
		return entityClass;
	}

	/**
	 * 查符合条件的首条件
	 * 
	 * @param repository 仓储
	 * @return
	 */
	public Map<String, Object> selectByFirst(IEntityMapper<TEntity> repository) {
		ExceptionUtils.checkNotNull(repository, "repository");
		return repository.selectBySpecifyFirst(this.builderSection());
	}

	/**
	 * 查询列表
	 * 
	 * @param repository 仓储
	 * @return
	 */
	public List<Map<String, Object>> selectByList(IEntityMapper<TEntity> repository) {
		ExceptionUtils.checkNotNull(repository, "repository");
		return repository.selectBySpecify(this.builderSection());
	}

}
